#include <iostream>
using namespace std;
#include <algorithm>
#include <assert.h>
#include <vector>

void print_sort(vector<int> &arr) {
  for (int i = 0; i < arr.size(); i++) {
    cout << arr[i] << " ";
  }
  cout << endl;
}

int _quick_sort(vector<int> &arr, int begin, int end) {
  int key = end;

  while (begin < end) {
    while (begin < end && arr[begin] <= arr[key]) {
      begin++;
    }
    while (begin < end && arr[end] >= arr[key]) {
      end--;
    }
    swap(arr[begin], arr[end]);
  }
  swap(arr[begin], arr[key]);
  return begin;
}

void quick_sort(vector<int> &arr, int left, int right) {
  assert(&arr);
  if (left > right)
    return;
  int div = _quick_sort(arr, left, right);
  // 开始递归排序各个区间
  _quick_sort(arr, left, div);
  _quick_sort(arr, div + 1, right);
}

// 快速排序
int m1() {
  int n;
  scanf("%d", &n);
  vector<int> arr(n);
  for (int i = 0; i < arr.size(); i++) {
    cin >> arr[i];
  }
  quick_sort(arr, 0, arr.size() - 1);

  print_sort(arr);

  return 0;
}

int pow(long long x, long long y) {
  if (y == 0) {
    return 1;
  }
  // 递归实现
  long long tmp = pow(x, y / 2);
  return y % 2 == 0 ? tmp * tmp : tmp * tmp * x;
}

int main() {
  long long a, b, p;
  cin >> a >> b >> p;
  long long ret = b > 0 ? pow(a, b) : pow(a, -b);
  ret = ret % p;

  cout << a << "^" << b << " mod " << p << "=" << ret << endl;

  return 0;
}
